<template>
	<u-navbar :title="title" @leftClick="leftClick" :bgColor="bgColor" :leftIcon="leftIcon" :titleStyle="titleStyle" :placeholder="placeholder"></u-navbar>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
// 统一用ui的样式
const titleStyle = {
	fontSize: "35rpx",
	fontFamily: "PingFang SC-Medium, PingFang SC",
	fontWeight: 500,
	color: "#333333"
};
interface Props {
	title: string;
	leftIcon: string;
	bgColor: string;
	placeholder: boolean;
}

const pages = getCurrentPages();

// 点击左侧返回图标
const leftClick = () => {
	if (pages.length > 1) {
		uni.navigateBack();
	} else {
		uni.navigateTo({
			url: "/pages/index/index"
		});
	}
};

const props = withDefaults(defineProps<Props>(), {
	title: "金师傅",
	leftIcon: "arrow-left",
	bgColor: "#ffffff",
	placeholder: true
});

const leftIcon = ref("arrow-left");

onMounted(() => {
	leftIcon.value = pages.length > 1 ? props.leftIcon : "home";
});
</script>

<style lang="scss" scoped></style>
